<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/ad_fragments :: head(~{::title})">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">
</head>

<body>
<!--导航-->
<nav th:replace="admin/ad_fragments :: menu(1)" class="ui inverted attached segment"></nav>

<div class="ui inverted attached pointing menu">
    <div class="ui container">
        <div id="sidebar-btn" class="ui basic inverted labeled icon button">
            <i class="sidebar icon"></i><h4 class="ui center aligned olive header item m-padded-mini">博客管理</h4>
        </div>
        <div class="right menu">
            <a href="#" th:href="@{/admin/blogs}" class="active item" style="color: #ffcbf0;"><i class="list icon"></i>列表</a>
            <a href="#" th:href="@{/admin/blogs/input}" class="item" style="color: #ffcbf0;"><i class="edit icon"></i>发布</a>
        </div>
    </div>
</div>
<!--  中间-->
<div class="m-container m-padded-tb-big">
    <div class="ui container">
        <!--        表单-->
        <form th:action="@{/admin/blogs/search}" method="post" class="ui segment form">
            <input type="hidden" name="page">
            <div class="inline fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <!--下拉菜单-->
                <div class="field">
                    <div class="ui labeled action input">
                        <div class="ui type selection dropdown">
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" data-value="1"
                                     th:data-value="${type.id}" th:text="${type.name}">日志
                                </div>
                            </div>
                        </div>
                    </div>
                    <button id="clear-btn" class="ui compact button">清空</button>
                </div>
                <!--                搜索框-->
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <button type="submit" id="search-btn" class="ui teal basic button">
                        <i class="search icon"></i>搜索
                    </button>
                </div>
                <!--             博客新增 -->
                <a href="#" th:href="@{/admin/blogs/input}" class="ui right floated teal basic button"><i
                        class="plus icon"></i>新增</a>
            </div>
        </form>
        <!--        表格-->
        <div id="table-container">
            <table th:fragment="blogList" class="ui compact celled table">
                <thead>
                <tr>
                    <th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>更新时间</th>
                    <th>操作</th>
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog, iterStat : ${pageInfo.list}">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">标题</td>
                    <td th:text="${blog.type.name}">分类名称</td>
                    <td th:text="${blog.recommend} ? '是' : '否'">是</td>
                    <td th:text="${blog.published} ? '发布' : '草稿'">草稿</td>
                    <td th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}"></td>
                    <td>
                        <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}"
                           class="ui mini teal basic button">编辑</a>
                        <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}"
                           class="ui mini red basic button">删除</a>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <th colspan="7">
                        <div class="ui inverted divided stackable grid">
                            <div class="two wide column" align="center">
                                <div class="item"><a th:href="@{/admin/blogs}">首页</a></div>
                            </div>
                            <div class="two wide column" align="center">
                                <div class="item"><a
                                        th:href="@{/admin/blogs(pageNum=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a>
                                </div>
                            </div>

                            <div class="eight wide m-text-thin column" align="center">
                                <p>第 <span th:text="${pageInfo.pageNum}"></span> 页，共 <span
                                        th:text="${pageInfo.pages}"></span> 页，有 <span
                                        th:text="${pageInfo.total}"></span> 篇文章</p>
                            </div>

                            <div class="two wide column" align="center">
                                <div class="item"><a
                                        th:href="@{/admin/blogs(pageNum=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a>
                                </div>
                            </div>
                            <div class="two wide column" align="center">
                                <div class="item"><a th:href="@{/admin/blogs(pageNum=${pageInfo.pages})}">尾页</a>
                                </div>
                            </div>
                        </div>
                    </th>
                </tr>
                </tfoot>
            </table>
            <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${message}">恭喜，操作成功！</p>
            </div>
        </div>
    </div>
</div>
<!--/*/<th:block th:replace="admin/ad_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<!--/*/</th:block>/*/-->
<!--利用jQuery获取到菜单-->
<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $("#sidebar-btn").click(function () {
        $(".ui.sidebar")
            .sidebar({
                transition: 'scale down' //默认uncover，可以取值push\overlay\slide along\slide out\scale down
            })
            .sidebar("toggle")
    });
    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    $('#clear-btn').on('click', function () {
        $('.ui.type.dropdown')
            .dropdown('clear');
    });
    $('.message .close')
        .on('click', function () {
            $(this)
                .closest('.message')
                .transition('fade')
            ;
        })
    ;

    function page(obj) {
        $("[name='page']").val($(obj).data("page"));  //拿到自定义的data-page中的值
        loaddata();
    }

    $("#search-btn").click(function () {
        $("[name='page']").val(0);
        loaddata();
    });

    function loaddata() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search", {
            title: $("[name = 'title']").val(),
            typeId: $("[name='typeId']").val(),
            recommend: $("[name='recommend']").prop('checked'),
            page: $("[name='page']").val()

        });
    }
</script>
</body>
</html>